package com.androidx.p013lv.mine.novel.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.bean.novel.LikeNovelBean;
import com.androidx.p013lv.base.dialog.BuyVipDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.OnClickListenTypes;
import com.androidx.p013lv.mine.databinding.FragmentMineBuyNovelBinding;
import com.androidx.p013lv.mine.novel.adpter.LikeNovelAdapterType;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

/* renamed from: com.androidx.lv.mine.novel.fragment.MineCollectNovelFragment */
public class MineCollectNovelFragment extends LazyFragment<FragmentMineBuyNovelBinding> implements ItemClickListener, OnRefreshLoadMoreListener, OnClickListenTypes {
    LikeNovelAdapterType adapter;
    int lastId = 0;

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
    }

    public static MineCollectNovelFragment newInstance() {
        Bundle bundle = new Bundle();
        bundle.putString("", "");
        MineCollectNovelFragment mineCollectNovelFragment = new MineCollectNovelFragment();
        mineCollectNovelFragment.setArguments(bundle);
        return mineCollectNovelFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.fragment_mine_buy_novel;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentMineBuyNovelBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentMineBuyNovelBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentMineBuyNovelBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.adapter = new LikeNovelAdapterType(this);
        ((FragmentMineBuyNovelBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(this);
        ((FragmentMineBuyNovelBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.novel.fragment.MineCollectNovelFragment.View$OnClickListenerC13771 */

            public void onClick(View view) {
                MineCollectNovelFragment.this.lastId = 0;
                MineCollectNovelFragment.this.getInfo();
            }
        });
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void onFirstUserVisible() {
        super.onFirstUserVisible();
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        String str;
        if (this.lastId == 0) {
            LikeNovelAdapterType likeNovelAdapterType = this.adapter;
            if (!(likeNovelAdapterType == null || likeNovelAdapterType.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((FragmentMineBuyNovelBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((FragmentMineBuyNovelBinding) this.binding).statusLayout.showLoading();
        }
        if (this.lastId == 0) {
            str = UrlManager.getInsatance().fictionLikeList("", 30);
        } else {
            str = UrlManager.getInsatance().fictionLikeList(String.valueOf(this.lastId), 30);
        }
        HttpUtils.getInsatance().get(str, new HttpCallback<BaseRes<LikeNovelBean>>("fictionLikeList") {
            /* class com.androidx.p013lv.mine.novel.fragment.MineCollectNovelFragment.C13782 */

            public void onLvSuccess(BaseRes<LikeNovelBean> baseRes) {
                ((FragmentMineBuyNovelBinding) MineCollectNovelFragment.this.binding).statusLayout.hideLoading();
                ((FragmentMineBuyNovelBinding) MineCollectNovelFragment.this.binding).refresh.finishRefresh();
                ((FragmentMineBuyNovelBinding) MineCollectNovelFragment.this.binding).refresh.finishLoadMore();
                if (baseRes.getCode() == 200) {
                    if (baseRes.getData() != null && baseRes.getData().getData() != null && baseRes.getData().getData().size() > 0) {
                        MineCollectNovelFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                        if (MineCollectNovelFragment.this.lastId == 0) {
                            MineCollectNovelFragment.this.adapter.setData(baseRes.getData().getData());
                            ((FragmentMineBuyNovelBinding) MineCollectNovelFragment.this.binding).refresh.resetNoMoreData();
                            return;
                        }
                        MineCollectNovelFragment.this.adapter.setDatasInEnd(baseRes.getData().getData());
                    } else if (MineCollectNovelFragment.this.lastId == 0) {
                        ((FragmentMineBuyNovelBinding) MineCollectNovelFragment.this.binding).statusLayout.showEmpty();
                    } else {
                        ((FragmentMineBuyNovelBinding) MineCollectNovelFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                    }
                } else if (MineCollectNovelFragment.this.lastId == 0) {
                    ((FragmentMineBuyNovelBinding) MineCollectNovelFragment.this.binding).statusLayout.showError();
                } else {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        getUserInfo();
    }

    public void getUserInfo() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userInfo(), JsonParams.build().commit(), new HttpCallback<BaseRes<UserInfo>>("userInfo") {
            /* class com.androidx.p013lv.mine.novel.fragment.MineCollectNovelFragment.C13793 */

            public void onLvSuccess(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() == 200) {
                    SpUtils.getInstance().setUserInfo(baseRes.getData());
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        LikeNovelBean.LikeNovelBeanData likeNovelBeanData = (LikeNovelBean.LikeNovelBeanData) this.adapter.getLastDataInPosition();
        if (likeNovelBeanData == null) {
            ((FragmentMineBuyNovelBinding) this.binding).refresh.finishLoadMore();
            ((FragmentMineBuyNovelBinding) this.binding).refresh.finishLoadMoreWithNoMoreData();
            return;
        }
        this.lastId = likeNovelBeanData.getFictionId();
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.lastId = 0;
        getInfo();
    }

    @Override // com.androidx.p013lv.mine.OnClickListenTypes
    public void onClick(LikeNovelBean.LikeNovelBeanData likeNovelBeanData, int i, int i2) {
        if (!isOnClick()) {
            if (i2 == C1207R.C1210id.ll_item_layouts) {
                if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                    new BuyVipDialog(getContext()).show();
                    return;
                } else {
                    ARouter.getInstance().build(Constance.NOVEL_ACTIVITY).withInt(Key.NOVEL_ID, likeNovelBeanData.getFictionId()).navigation();
                }
            }
            if (i2 != C1207R.C1210id.ll_item_layout) {
                return;
            }
            if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                new BuyVipDialog(getContext()).show();
                return;
            }
            ARouter.getInstance().build(Constance.VOICE_NOVEL_ACTIVITY_NEW).withInt(Key.NOVEL_ID, likeNovelBeanData.getFictionId()).navigation();
        }
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag("fictionLikeList");
        HttpUtils.getInsatance().cancelTag("userInfo");
    }
}
